package com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.CommonConstraint;
import com.dao.InfoDAO;
import com.entity.Info;

@Transactional
@Service
public class InfoService {
	@Autowired
	private InfoDAO infoDAO;
	public List<Info> findTopNews(int num){
		return this.infoDAO.findByType(CommonConstraint.NEWS, 0, num);
	}
	
	public Info findAbout(){
		List<Info> list = this.infoDAO.findByType(CommonConstraint.ABOUT, 0, 1);
		if(list != null && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public Info findContact(){
		List<Info> list = this.infoDAO.findByType(CommonConstraint.CONTACT, 0, 1);
		if(list != null && list.size() > 0){
			return list.get(0);
		}
		return null;
	}
	public List<Info> findNewsInPage(int start, int limit){
		return this.infoDAO.findByType(CommonConstraint.NEWS, start, limit);
	}
	public int findNewsCount(){
		return this.infoDAO.findCountByType(CommonConstraint.NEWS);
	}
	public Info findById(int id){
		return this.infoDAO.find(id);
	}
	public List<Info> findRelateNews(String[] tags){
		return this.infoDAO.findRelated(tags);
	}
}
